package com.qingxin.sys.verifier.rules;

import java.util.HashMap;
import java.util.Map;

import com.qingxin.sys.verifier.FormMap;
import com.qingxin.sys.verifier.VerifyRule;

/**
 * 下拉框非空验证[ligerComboBox]<br>
 * @author Administrator
 *
 */
public class ComboxRule extends VerifyRule {

	private String valueid;
	private String valuename;
	
	
	public ComboxRule() {
		this.valueid = "";
	}
	
	
	@Override
	public boolean isValid(String name, String label, FormMap formMap) {
		String value = formMap.getParameter(valuename);
		if(!isEmpty(value)){
			return true;//非空
		}
		message = createMessage(null, "{name}", label, "{label}", label);
		
		return false;
	}
	
	
	@Override
	public Map<String, Object> getRuleCfg(String name, String label) {
		if(isEmpty(getValueid())){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rtype", "combox");
		map.put("valueid", getValueid());
		
		String errormsg = createMessage(null, "{name}", label, "{label}", label);
		if(!isEmpty(errormsg)){
			map.put("error", errormsg);
		}
		
		return map;
	}
	

	public String getValueid() {
		if(isEmpty(valueid)){
			return valuename;
		}
		return valueid;
	}
	public void setValueid(String valueid) {
		this.valueid = valueid;
	}
	public String getValuename() {
		return valuename;
	}
	public void setValuename(String valuename) {
		this.valuename = valuename;
	}
	
	
}
